package com.glsc.ngateway.common.base.domain.mysql.opmanage.report.subscribe;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigInteger;
import java.time.LocalDateTime;

/**
 * @author: qiyr
 * @date: 2022/6/10 10:44
 * @description: 报表订阅任务表
 */
@Entity
@Table(name = "t_user_report_subscribe_task")
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class UserReportSubscribeTask {
    /**
     * 自增主键id
     */
    @Id
    @Column(name = "id" , columnDefinition = "bigint")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private BigInteger id;

    /**
     * 用户报表订阅id
     */
    @Column(name = "subscribe_id")
    private String subscribeId;

    /**
     * 邮件id
     */
    @Column(name = "mail_id" , columnDefinition = "bigint")
    private BigInteger mailId;

    /**
     * 报表参数
     */
    @Column(name = "report_mail_info")
    private String reportMailInfo;

    /**
     * 收件人名称
     */
    @Column(name = "username")
    private String username;

    /**
     * 收件人邮箱
     */
    @Column(name = "user_email")
    private String userEmail;

    /**
     * 任务状态（0：待生成，1：生成中，2：生成成功，3：生成失败）
     */
    @Column(name = "task_status")
    private String taskStatus;

    /**
     * 任务结果
     */
    @Column(name = "task_msg")
    private String taskMsg;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "create_time", insertable = false, updatable = false)
    private LocalDateTime createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "update_time", insertable = false, updatable = false)
    private LocalDateTime updateTime;

    public UserReportSubscribeTask() {
    }

    public BigInteger getId() {
        return id;
    }

    public void setId(BigInteger id) {
        this.id = id;
    }

    public String getSubscribeId() {
        return subscribeId;
    }

    public void setSubscribeId(String subscribeId) {
        this.subscribeId = subscribeId;
    }

    public BigInteger getMailId() {
        return mailId;
    }

    public void setMailId(BigInteger mailId) {
        this.mailId = mailId;
    }

    public String getReportMailInfo() {
        return reportMailInfo;
    }

    public void setReportMailInfo(String reportMailInfo) {
        this.reportMailInfo = reportMailInfo;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(String taskStatus) {
        this.taskStatus = taskStatus;
    }

    public String getTaskMsg() {
        return taskMsg;
    }

    public void setTaskMsg(String taskMsg) {
        this.taskMsg = taskMsg;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }


    public static final class Builder {
        private BigInteger id;
        private String subscribeId;
        private BigInteger mailId;
        private String reportMailInfo;
        private String username;
        private String userEmail;
        private String taskStatus;
        private String taskMsg;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;

        public Builder() {
        }

        public Builder id(BigInteger id) {
            this.id = id;
            return this;
        }

        public Builder subscribeId(String subscribeId) {
            this.subscribeId = subscribeId;
            return this;
        }

        public Builder mailId(BigInteger mailId) {
            this.mailId = mailId;
            return this;
        }

        public Builder reportMailInfo(String reportMailInfo) {
            this.reportMailInfo = reportMailInfo;
            return this;
        }

        public Builder username(String username) {
            this.username = username;
            return this;
        }

        public Builder userEmail(String userEmail) {
            this.userEmail = userEmail;
            return this;
        }

        public Builder taskStatus(String taskStatus) {
            this.taskStatus = taskStatus;
            return this;
        }

        public Builder taskMsg(String taskMsg) {
            this.taskMsg = taskMsg;
            return this;
        }

        public Builder createTime(LocalDateTime createTime) {
            this.createTime = createTime;
            return this;
        }

        public Builder updateTime(LocalDateTime updateTime) {
            this.updateTime = updateTime;
            return this;
        }

        public UserReportSubscribeTask build() {
            UserReportSubscribeTask userReportSubscribeTask = new UserReportSubscribeTask();
            userReportSubscribeTask.setId(id);
            userReportSubscribeTask.setSubscribeId(subscribeId);
            userReportSubscribeTask.setMailId(mailId);
            userReportSubscribeTask.setReportMailInfo(reportMailInfo);
            userReportSubscribeTask.setUsername(username);
            userReportSubscribeTask.setUserEmail(userEmail);
            userReportSubscribeTask.setTaskStatus(taskStatus);
            userReportSubscribeTask.setTaskMsg(taskMsg);
            userReportSubscribeTask.setCreateTime(createTime);
            userReportSubscribeTask.setUpdateTime(updateTime);
            return userReportSubscribeTask;
        }
    }
}